{% extends 'layout/mange.html' %}

{% block title %} 搜索结果 {% endblock %}

{% block content %}
    <div class="container-fluid">
        <div class="row">
            <div class="col-md-12">
                <h2>搜索结果</h2>
                <hr>
            </div>
        </div>

        <!-- 搜索表单 -->
        <div class="row">
            <div class="col-md-12">
                <div class="panel panel-default">
                    <div class="panel-body">
                        <form method="get" class="form-inline">
                            <div class="form-group">
                                {{ form.search_query }}
                            </div>
                            <div class="form-group ml-2">
                                {{ form.search_type }}
                            </div>
                            <button type="submit" class="btn btn-primary ml-2">搜索</button>
                        </form>
                    </div>
                </div>
            </div>
        </div>

        <!-- 搜索结果 -->
        <div class="row">
            <!-- 项目结果 -->
            <div class="col-md-12">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title">项目结果 ({{ results.projects|length }})</h3>
                    </div>
                    <div class="panel-body">
                        {% if results.projects %}
                            <table class="table table-hover">
                                <thead>
                                    <tr>
                                        <th>项目名称</th>
                                        <th>描述</th>
                                        <th>创建时间</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    {% for project in results.projects %}
                                    <tr>
                                        <td><a href="{% url 'project_detail' project.id %}">{{ project.name }}</a></td>
                                        <td>{{ project.description|truncatechars:50 }}</td>
                                        <td>{{ project.create_datetime|date:'Y-m-d' }}</td>
                                        <td>
                                            <a href="{% url 'bug_list' project.id %}" class="btn btn-xs btn-info">查看BUG</a>
                                        </td>
                                    </tr>
                                    {% endfor %}
                                </tbody>
                            </table>
                        {% else %}
                            <p class="text-center text-muted">没有找到匹配的项目</p>
                        {% endif %}
                    </div>
                </div>
            </div>

            <!-- BUG结果 -->
            <div class="col-md-12">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title">BUG结果 ({{ results.bugs|length }})</h3>
                    </div>
                    <div class="panel-body">
                        {% if results.bugs %}
                            <table class="table table-hover">
                                <thead>
                                    <tr>
                                        <th>标题</th>
                                        <th>所属项目</th>
                                        <th>状态</th>
                                        <th>优先级</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    {% for bug in results.bugs %}
                                    <tr>
                                        <td><a href="{% url 'bug_detail' bug.project.id bug.id %}">{{ bug.title }}</a></td>
                                        <td><a href="{% url 'project_detail' bug.project.id %}">{{ bug.project.name }}</a></td>
                                        <td><span class="label" style="background-color: #{{ bug.project.color }};">{{ bug.status.name }}</span></td>
                                        <td>{{ bug.priority.name }}</td>
                                        <td>
                                            <a href="{% url 'bug_detail' bug.project.id bug.id %}" class="btn btn-xs btn-info">查看详情</a>
                                        </td>
                                    </tr>
                                    {% endfor %}
                                </tbody>
                            </table>
                        {% else %}
                            <p class="text-center text-muted">没有找到匹配的BUG</p>
                        {% endif %}
                    </div>
                </div>
            </div>

            <!-- 任务结果 (假设存在Task模型) -->
            <div class="col-md-12">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title">任务结果 ({{ results.tasks|length }})</h3>
                    </div>
                    <div class="panel-body">
                        {% if results.tasks %}
                            <table class="table table-hover">
                                <thead>
                                    <tr>
                                        <th>标题</th>
                                        <th>所属项目</th>
                                        <th>状态</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    {% for task in results.tasks %}
                                    <tr>
                                        <td>{{ task.title }}</td>
                                        <td><a href="{% url 'project_detail' task.project.id %}">{{ task.project.name }}</a></td>
                                        <td>{{ task.status }}</td>
                                        <td>
                                            <a href="#" class="btn btn-xs btn-info">查看详情</a>
                                        </td>
                                    </tr>
                                    {% endfor %}
                                </tbody>
                            </table>
                        {% else %}
                            <p class="text-center text-muted">没有找到匹配的任务</p>
                        {% endif %}
                    </div>
                </div>
            </div>
        </div>
    </div>
{% endblock %}